package ssw.game.engine;

import java.util.SortedSet;
import java.util.TreeSet;

import ssw.game.GameType;

public class GameDictionary {
	private static final GameDictionary INSTANCE = new GameDictionary();

	private final SortedSet<String> words = new TreeSet<String>();

	private GameDictionary()  {
		super();
		for (String word : ALL_WORDS.split(","))  {
			words.add(word);
		}
	}

	private static final String ALL_WORDS = 
		"AA,AB,AD,AE,AG,AH,AI,AL,AM,AN,AR,AS,AT,AW,AX,AY," +
		"BA,BE,BI,BO,BY,DE,DO,ED,EF,EH,EL,EM,EN,ER,ES,ET,EX," +
		"FA,FE,GO,HA,HE,HI,HM,HO,ID,IF,IN,IS,IT,JO,KA,KI," +
		"LA,LI,LO,MA,ME,MI,MM,MO,MU,MY,NA,NE,NO,NU," +
		"OD,OE,OF,OH,OI,OM,ON,OP,OR,OS,OW,OX,OY,PA,PE,PI," +
		"QI,RE,SH,SI,SO,TA,TI,TO,UH,UM,UN,UP,US,UT," + 
		"WE,WO,XI,XU,YA,YE,YO,ZA," +
		"AAH,AAL,AAS,ABA,ABO,ABS,ABY,ACE,ACT,ADD,ADO,ADS,ADZ,AFF,AFT,AGA,AGE,AGO,AHA,AID," +
		"AIL,AIM,AIN,AIR,AIS,AIT,ALA,ALB,ALE,ALL,ALP,ALS,ALT,AMA,AMI,AMP,AMU,ANA,AND,ANE," + 
		"ANI,ANT,ANY,APE,APT,ARB,ARC,ARE,ARF,ARK,ARM,ARS,ART,ASH,ASK,ASP,ASS,ATE,ATT,AUK," + 
		"AVA,AVE,AVO,AWA,AWE,AWL,AWN,AXE,AYE,AYS,AZO," + 
		"BAA,BAD,BAG,BAH,BAL,BAM,BAN,BAP,BAR,BAS,BAT,BAY,BED,BEE,BEG,BEL,BEN,BET,BEY,BIB," + 
		"BID,BIG,BIN,BIO,BIS,BIT,BIZ,BOA,BOB,BOD,BOG,BOO,BOP,BOS,BOT,BOW,BOX,BOY,BRA,BRO," + 
		"BRR,BUB,BUD,BUG,BUM,BUN,BUR,BUS,BUT,BUY,BYE,BYS,"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TOW,TOY,TRY,TSK,TUB,TUG,TUI,TUN,TUP,TUT,TUX,TWA,TWO,TYE,"+ 
		"UDO,UGH,UKE,ULU,UMM,UMP,UNS,UPO,UPS,URB,URD,URN,USE,UTA,UTS,"+ 
		"VAC,VAN,VAR,VAS,VAT,VAU,VAV,VAW,VEE,VEG,VET,VEX,VIA,VIE,VIG,VIM,VIS,VOE,VOW,VOX,VUG,"+ 
		"WAB,WAD,WAE,WAG,WAN,WAP,WAR,WAS,WAT,WAW,WAX,WAY,WEB,WED,WEE,WEN,WET,WHA,WHO,WHY,"+ 
		"WIG,WIN,WIS,WIT,WIZ,WOE,WOG,WOK,WON,WOO,WOP,WOS,WOT,WOW,WRY,WUD,WYE,WYN,XIS,"+ 
		"YAH,YAK,YAM,YAP,YAR,YAW,YAY,YEA,YEH,YEN,YEP,YES,YET,YEW,YID,YIN,YIP,YOB,YOD,YOK,"+ 
		"YOM,YON,YOU,YOW,YUK,YUM,YUP,ZAG,ZAP,ZAX,ZED,ZEE,ZEK,ZIG,ZIN,ZIP,ZIT,ZOA,ZOO";
	
	public static SortedSet<String> makeWordList(GameType type) {
		SortedSet<String> words = new TreeSet<String>();

		for (String word : INSTANCE.words)  {
			if (type.accept(word, INSTANCE))  {
				words.add(word);
			}
		}
		
		return words;
	}
	
	public boolean contains(String word)  {
		return words.contains(word);
	}
}

/*
AA	rough, cindery lava
AB	abdominal muscle {OSPD3}
AD	advertisement
AE	one
AG	pert. to agriculture
AH	to exclaim in amazement
AI	three-toed sloth
AL	East Indian tree
AM	[be-conj] (to exist)
AN	indefinite article
AR	letter 'r'
AS	to the same degree
AT	in the location of
AW	intj. expressing disbelief
AX	to cut with an ax
AY	aye
BA	eternal soul in Egyptian mythology 
BE	to exist
BI	bisexual
BO	pal
BY	side issue

DE	of, from
DO	to execute/first tone of musical scale

ED	education {OSPD3}
EF	letter 'f' 
EH	intj. used to indicate lack of understanding
EL	letter 'l'
EM	printer's measurement
EN	printer's measurement
ER	intj. expressing hesitation

ES	letter 's'
ET	[eat-conj] (to consume)
EX	letter 'x'

FA	fourth tone of diatonic musical scale 
FE	Hebrew letter (feh, pe) {OSPD4}

GO	to leave/Japanese board game
HA	sound expressing triumph
HE	male person
HI	intj. used as a greeting
HM	intj. expressing thought (hmm)
HO	intj. used to attract attention to something
ID	part of psyche related to instinctual impulses 
IF	possible condition
IN	influence
IS	[be-conj] (to exist)
IT	person playing tag/indefinite pronoun
JO	sweetheart 
KA	Egyptian spiritual self 
KI	vital life-sustaining energy force (qi) {OSPD4}

LA	sixth tone of diatonic musical scale
LI	Chinese unit of distance
LO	intj. used to attract attention
MA	mother 
ME	pronoun referring to myself
MI	third tone of diatonic musical scale
MM	intj. expressing satisfaction
MO	moment
MU	Greek letter
MY	possessive prounoun

NA	no 
NE	born with the name of (nee)
NO	negative reply
NU	Greek letter

OD	hypothetical force of natural power 
OE	Faroean wind
OF	coming from
OH	to exclaim "oh"
OI	intj. expressing dismay (oy) {OSPD4}
OM	mantra used in meditation
ON	side of wicket where cricket batsman stands
OP	style of abstract art
OR	heraldic color gold
OS	orifice/bone/ridge of sand (esker)
OW	intj. expressing sudden pain
OX	hoofed mammal/clumsy person
OY	intj. expressing dismay

PA	father 
PE	Hebrew letter
PI	Greek letter/to jumble
QI	vital life-sustaining energy force {OSPD4}

RE	second tone of diatonic musical scale 
SH	intj. used to urge silence (shh) 
SI	seventh tone of diatonic musical scale (ti)
SO	fifth tone of diatonic musical scale
TA	thanks 

TI	seventh tone of diatonic musical scale
TO	toward
UH	intj. expressing hesitation 
UM	intj. expressing hesitation
UN	one

UP	to raise
US	objective pronoun for "we"
UT	musical tone in French solmization system
WE	plural pronoun 
WO	woe

XI	Greek letter 
XU	Vietnamese monetary unit
YA	you 
YE	you
YO	intj. used to call attention {OSPD3}

ZA	pizza {OSPD4}
*/